﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.WindowsAzure.ServiceRuntime;
using Microsoft.WindowsAzure.Diagnostics;
using Microsoft.WindowsAzure;
using System.Net;

namespace AzureToolkit.Engine
{
    public abstract class RoleEntryPointBase : RoleEntryPoint
    {


        public override bool OnStart()
        {

            Diagnostics.Setup();

            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
            RoleEnvironment.Changing += RoleEnvironmentChanging;

            // Set the maximum number of concurrent connections 
            ServicePointManager.DefaultConnectionLimit = 12 * Environment.ProcessorCount;

            return base.OnStart();
        }

        protected virtual void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
        {
            // If a configuration setting is changing
            if (e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange))
            {
                // Set e.Cancel to true to restart this role instance
                e.Cancel = true;
            }
        }

    }
}
